const course = require('./../server/courseServer');
let courseServer = new course();
function course_server() {
    let result = {};
    this.queryCourse = (req,res) => {
        courseServer.queryCourse(req,rows => {
            if (rows){
                result.code=1;
                result.data = rows;
            } else{
                result.code=0;
                result.data = null;
            }
            res.write(JSON.stringify(result));
            res.end();
        })
    }
    this.add = (req,res) => {
        courseServer.add(req.body,rows => {
            if (rows){
                result.code=1;
                result.msg = '发布成功';
            } else{
                result.code=0;
                result.msg = '发布失败';
            }
            res.write(JSON.stringify(result));
            res.end();
        })
    }
    this.del = (req,res) => {
        courseServer.del(req.body, rows => {
            if (rows){
                result.code=1;
                result.msg = '删除成功';
            } else{
                result.code=0;
                result.msg = '删除失败';
            }
            res.write(JSON.stringify(result));
            res.end();
        })
    }
    this.delAll = (req,res) => {
        courseServer.delAll(req.body, rows => {
            if (rows){
                result.code=1;
                result.msg = '批量删除成功';
            } else{
                result.code=0;
                result.msg = '批量删除失败';
            }
            res.write(JSON.stringify(result));
            res.end();
        })
    }
    this.search = (req,res) => {
        courseServer.search(req.body, rows => {
            if (rows){
                result.code=1;
                result.data = rows;
            } else{
                result.code=0;
                result.msg = '查询失败';
            }
            res.write(JSON.stringify(result));
            res.end();
        })
    }
}
module.exports = course_server;
